+2008-03-20 Tor Lillqvist <tml@novell.com>
+
+ Bug 314084 - GTK+ dialogs should not be placed partially offscreen
+
+ * gtk/gtkwindow.c (clamp): New function. Clamps a window position
+ in one dimension, or centered in case it doesn't fit.
+ (clamp_window_to_rectangle): Simplify. Call clamp() for x and y
+ dimensions.
+
2008-03-18 Tor Lillqvist <tml@novell.com>
Bug 523225 - modules/input/im*.c: MODULE_ENTRY macros make illegal code
*y = monitor.y;
}
+static void
+clamp (gint *base,
+ gint extent,
+ gint clamp_base,
+ gint clamp_extent)
+{
+ if (extent > clamp_extent)
+ /* Center */
+ *base = clamp_base + clamp_extent/2 - extent/2;
+ else if (*base < clamp_base)
+ *base = clamp_base;
+ else if (*base + extent > clamp_base + clamp_extent)
+ *base = clamp_base + clamp_extent - extent;
+}
+
static void
clamp_window_to_rectangle (gint *x,
gint *y,
gint h,
const GdkRectangle *rect)
{
- gint outside_w, outside_h;
-
- outside_w = (*x + w) - (rect->x + rect->width);
- if (outside_w > 0)
- *x -= outside_w;
-
- outside_h = (*y + h) - (rect->y + rect->height);
- if (outside_h > 0)
- *y -= outside_h;
+#ifdef DEBUGGING_OUTPUT
+ g_print ("%s: %+d%+d %dx%d: %+d%+d: %dx%d", __FUNCTION__, rect->x, rect->y, rect->width, rect->height, *x, *y, w, h);
+#endif
- /* if larger than the screen, center on the screen. */
- if (*x < rect->x)
- *x += (rect->x - *x) / 2;
- if (*y < rect->y)
- *y += (rect->y - *y) / 2;
+ /* If it is too large, center it. If it fits on the monitor but is
+ * partially outside, move it to the closest edge. Do this
+ * separately in x and y directions.
+ */
+ clamp (x, w, rect->x, rect->width);
+ clamp (y, h, rect->y, rect->height);
+#ifdef DEBUGGING_OUTPUT
+ g_print (" ==> %+d%+d: %dx%d\n", *x, *y, w, h);
+#endif
}